﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Castle.ActiveRecord;
using Castle.ActiveRecord.Queries;
using NHibernate.Criterion;
using System.Collections;

/// <summary>
/// Summary description for Tour
/// </summary>
namespace LIB
{
    [ActiveRecord("Content")]
    public class Content_Info : ActiveRecordBase<Content_Info>
    {
        private int _id;
        private string _contentTitle;
        private string _contentAvatar;
        private string _contentSummary;
        private string _contentDes;
        private int _contentVisited;
        private DateTime _contentDate;
        private Category_Info _contentCatID;
        private int _contentOrder;
        private bool _contentIsVisible;

         [PrimaryKey(PrimaryKeyType.Native)]
        public int id
        {
            get { return _id; }
            set { _id = value; }
        }
         [Property]
         public int contentOrder
         {
             get { return _contentOrder; }
             set { _contentOrder = value; }
         }
         [Property]
         public bool contentIsVisible
         {
             get { return _contentIsVisible; }
             set { _contentIsVisible = value; }
         }
         [Property]
        public string contentTitle
        {
            get { return _contentTitle; }
            set { _contentTitle = value; }
        }
         [Property]
         public int contentVisited
         {
             get { return _contentVisited; }
             set { _contentVisited = value; }
         }
         [Property]
        public string contentAvatar
        {
            get { return _contentAvatar; }
            set { _contentAvatar = value; }
        }
         [Property]
        public string contentSummary
        {
            get { return _contentSummary; }
            set { _contentSummary = value; }
        }
         [Property]
        public string contentDes
        {
            get { return _contentDes; }
            set { _contentDes = value; }
        }
         [Property]
        public DateTime contentDate
        {
            get { return _contentDate; }
            set { _contentDate = value; }
        }
        [BelongsTo("contentCatID")]
        public Category_Info contentCatID
        {
            get { return _contentCatID; }
            set { _contentCatID = value; }
        }
        public static Content_Info[] getNewsInCatByLanguage(int catID)
        {
            SimpleQuery q = new SimpleQuery(typeof(Content_Info), QueryLanguage.Sql, @"EXEC getNewsInCatByLanguage @catID=?", new object[] { catID });
            q.AddSqlReturnDefinition(typeof(Content_Info), "listDes");
            Content_Info[] des = (Content_Info[])ExecuteQuery(q);
            return des;
        }
        public static Content_Info[] searchNews(int catID, int phanloaID)
        {
            SimpleQuery q = new SimpleQuery(typeof(Content_Info), QueryLanguage.Sql, @"EXEC searchNews @catID=?,@phanloaID=?", new object[] { catID,phanloaID });
            q.AddSqlReturnDefinition(typeof(Content_Info), "listDes");
            Content_Info[] des = (Content_Info[])ExecuteQuery(q);
            return des;
        }
    }
}
